﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BotvaBot.RequestChains.Base;
using BotvaBot.RequestChainItems;

namespace BotvaBot.RequestChains
{
    public class SendLetunToBigAdventureChain : BotvaChainBase
    {
        public SendLetunToBigAdventureChain()
            : base()
        { }

        public SendLetunToBigAdventureChain(BotvaChainContext parentContext)
            : base(parentContext)
        { }


        public int GildiaId { get; set; }
        public int LetunId { get; set; }

        public override void Init()
        {
            base.Init();

            AddItem(new EnterChainItem(), () => !WithInheritedContext);
            AddItem(new LoginChainItem(), () => !WithInheritedContext);
            AddItem(new GotoCastleChainItem());
            AddItem(new GotoGildiaChainItem());
            AddItem(new GotoIncubatorChainItem());
            AddItem(new PrepareLetunToBigAdventureChainItem());
            AddItem(new SendLetunToBigAdventureChainItem());
            AddItem(new LogoutChainItem(), () => !WithInheritedContext);
        }

        protected override void PrepareRunChain()
        {
            base.PrepareRunChain();

            GotoGildiaChainItem gotoGildiaChainItem = Chain.Values
                .Where(chi => chi.GetType() == typeof(GotoGildiaChainItem)).First() as GotoGildiaChainItem;
            gotoGildiaChainItem.GildiaId = GildiaId;

            GotoIncubatorChainItem gotoIncubatorChainItem = Chain.Values
                .Where(chi => chi.GetType() == typeof(GotoIncubatorChainItem)).First() as GotoIncubatorChainItem;
            gotoIncubatorChainItem.GildiaId = GildiaId;

            PrepareLetunToBigAdventureChainItem prepareLetunToBigAdventureChainItem = Chain.Values
                .Where(chi => chi.GetType() == typeof(PrepareLetunToBigAdventureChainItem)).First() as PrepareLetunToBigAdventureChainItem;
            prepareLetunToBigAdventureChainItem.GildiaId = GildiaId;
            prepareLetunToBigAdventureChainItem.LetunId = LetunId;

            SendLetunToBigAdventureChainItem sendLetunToBigAdventureChainItem = Chain.Values
                .Where(chi => chi.GetType() == typeof(SendLetunToBigAdventureChainItem)).First() as SendLetunToBigAdventureChainItem;
            sendLetunToBigAdventureChainItem.GildiaId = GildiaId;
        }

    }
}
